package com.dahafo.bootmybatis.Mapper;

import com.dahafo.bootmybatis.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("SELECT * FROM USER WHERE NAME= #{name}")
    User findByName(@Param("name") String name);

    @Insert("INSERT INTO USER(NAME,AGE) VALUES(#{name}, #{age})")
    int inster(@Param("name") String name, @Param("age") Integer age);

    @Update("UPDATE USER SET AGE=#{age} WHERE NAME=#{name}")
    void update(User user);

    @Delete("DELETE FROM USER WHERE ID=#{id}")
    void delete(Long id);

    @Delete("DELETE FROM USER WHERE NAME=#{name}")
    void deleteByName(String name);

    @Results({
            @Result(property = "name", column = "NAME"),
            @Result(property = "age", column = "AGE")
    })
    @Select("SELECT * FROM USER")
    List<User> findAll();
}
